package com.nanfang51g3.ckz.ui.money.add.pay;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.application.CkzApplication;
import com.nanfang51g3.ckz.ui.base.IPresenter;
import com.nanfang51g3.ckz.ui.base.Base2Activity;
import com.nanfang51g3.ckz.utils.AppManager;
import com.nanfang51g3.ckz.utils.ButtonUtils;
import com.nanfang51g3.ckz.utils.EasyToast;
import com.nanfang51g3.ckz.utils.KLog;
import com.nanfang51g3.ckz.widget.ClearEditText;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/4/19.
 */
public class AddALiPayActivity extends Base2Activity implements AddALiPayContract.View {
    AddALiPayContract.AddALiPayActionsListener addALiPayActionsListener;
    @Bind(R.id.index_tv_right_title)
    TextView indexTvRightTitle;
    @Bind(R.id.cet_add_ali_pay_name)
    ClearEditText cetAddAliPayName;
    @Bind(R.id.cet_add_ali_pay_phone)
    ClearEditText cetAddAliPayPhone;


    @Override
    public int getContentView() {
        return R.layout.add_ali_pay;
    }
    @Override
    public IPresenter getPresenter() {
        return null;
    }
    @Override
    public boolean isShowLeftIcon() {
        return true;
    }

    @Override
    public boolean isShowRightIcon() {
        return false;
    }

    @Override
    public int setLeftIcon() {
        return R.mipmap.ic_accounting_left;
    }

    @Override
    public int setRightIcon() {
        return 0;
    }

    @Override
    public int showTitle() {
        return R.string.str_add_ali_pay_detail;
    }

    @Override
    public void onClickLeft(View v) {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    public void onClickRight(View v) {
        EasyToast.showShort(this, "msg");
    }

    @Override
    public void showMessage(String message) {
        EasyToast
                .showShort(this, message);
    }

    @Override
    public void finalView() {
        AppManager.getAppManager().finishActivity(this);

    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addALiPayActionsListener = DaggerAddALiPayContractComponent
                .builder()
                .appComponent(CkzApplication.getAppComponent())
                .addALiPayPresenterModule(new AddALiPayPresenterModule(this))
                .build().getAddALiPayPresenter();
        KLog.i("TAG", addALiPayActionsListener == null ? "addALiPayActionsListener==null" : "addALiPayActionsListener!=null");
        ButterKnife.bind(this);
        indexTvRightTitle.setVisibility(View.VISIBLE);
        indexTvRightTitle.setText(R.string.str_save);

    }

    @OnClick(R.id.index_tv_right_title)
    public void index_tv_right_title(View view) {
        if (!ButtonUtils.isFastDoubleClick(R.id.index_tv_right_title)) {
            String aliPayName = cetAddAliPayName.getText().toString().trim();
            String aliPayphone = cetAddAliPayPhone.getText().toString().trim();

            /**
             * @see AddALiPayPresenter#addLiPay(String)
             */
            addALiPayActionsListener.addLiPay(aliPayName,aliPayphone);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);//解除绑定，官方文档只对fragment做了解绑
    }
}
